import axios from 'axios';

export default {
    listTabs: () => {
        return axios.get('/seeyon/rest/bhtTaskIndex/index');
    },
    // category-主分类;subCategory-子分类
    listStateByTabs: param => {
        let type = top.location.href.split('type=')[1]
        if(param.maintenance) {
            return axios.get(`/seeyon/rest/bhtTaskIndex/state/${param.category}/${param.subCategory}/1/${type}`);
        } else {
            return axios.get(`/seeyon/rest/bhtTaskIndex/state/${param.category}/${param.subCategory}/0/${type}`);
        }
    },
    // category-主分类;subCategory-子分类
    listTableByState: (param, search) => {
        const pageNo = param.pageNo || 1;
        const pageSize = param.pageSize || 30;
        const category = param.category || 1;
        const subCategory = param.subCategory || -1;
        const state = param.state;
        const showCycle = param.showCycle ? 1 : -1;
        let type = top.location.href.split('type=')[1]
        let url = `/seeyon/rest/bhtTask/search/${pageNo}/${pageSize}/${type}?category=${category}&subCategory=${subCategory}&state=${state}`;
        if (param.hasOwnProperty('showComplete')) {
            url += '&showComplete=' + (param.showComplete ? 1 : -1);
        }
        if (param.hasOwnProperty('maintenance')) {
            url += '&isMaintenance=' + (param.maintenance ? 1 : 0);
        }
        url += '&showCycle=' + showCycle;
        //search['folder'] = false;
        // search.type = 'ziYou'
        return axios.post(url, search);
    },
    listChildTableByState: (param, obj) => {
        const taskId = param.taskId || 1;
        const state = param.state || 0;
        const subCategory = param.subCategory || -1;
        const folder = !!param.folder;
        const showComplete = param.showComplete ? 1 : -1;
        const showCycle = param.showCycle ? 1 : -1;

        return axios.post(
            `/seeyon/rest/bhtTask/children/${taskId}/${state}?subCategory=${subCategory}&folder=${folder}&showComplete=${showComplete}&showCycle=${showCycle}`,
            obj
        );
    },
    dragTable: param => {
        return axios.post(`/seeyon/rest/bhtTask/move`, param);
    },
    modifyFrontTask: param => {
        return axios.post(`/seeyon/rest/taskDetail/frontTask`, param);
    },
    updateProgress: param => {
        return axios.post(`/seeyon/rest/taskDetail/updateProgress`, param);
    },
    upgrade: param => {
        return axios.get(`/seeyon/rest/bhtTask/upgrade/${param.taskId}`);
    },
    degrade: param => {
        return axios.get(`/seeyon/rest/bhtTask/degrade/${param.taskId}`);
    },
    startCycleTask: param => {
        return axios.get(`/seeyon/rest/bhtTask/cycleTask/${param.taskId}?opera=start`);
    },
    stopCycleTask: param => {
        return axios.get(`/seeyon/rest/bhtTask/cycleTask/${param.taskId}?opera=stop`);
    },
    stopAndCloseCycleTask: param => {
        return axios.get(`/seeyon/rest/bhtTask/cycleTask/${param.taskId}?opera=stopAndClose`);
    },
    restoreCycleTask: param => {
        return axios.get(`/seeyon/rest/bhtTask/cycleTask/${param.taskId}?opera=restore`);
    },
    restoreAndStartCycleTask: param => {
        return axios.get(`/seeyon/rest/bhtTask/cycleTask/${param.taskId}?opera=restoreAndStart`);
    },
    delTask: param => {
        return axios.post(`/seeyon/rest/taskDetail/modify/7`, param);
    },
    trueDelTask: param => {
        return axios.post(`/seeyon/rest/bhtTask/delete`, param);
    },
    recoveryTask: param => {
        return axios.post(`/seeyon/rest/taskDetail/recoveryTask`, param);
    },
    urgingTask: param => {
        return axios.post(`/seeyon/rest/taskDetail/urgingTask`, param);
    },
    listEnumList: param => {
        return axios.get(`/seeyon/rest/bhtTaskIndex/enum/${param.enumName}`);
    },
    copyTask: param => {
        return axios.post(`/seeyon/rest/bhtTask/copy`, param);
    },
    getCurrentUser: ()=> {
        return axios.get('/seeyon/rest/bhtTaskIndex/currentUser');
    }
};
